(function () {
    // var data = [
    //     { value: 1300},
    //     { value: 310},
    //     { value: 600}
    // ]
    // var total = data.reduce(function (a, b, arr) {
    //     console.log(a.value, b.value)
    //     return {value: a.value + b.value}
    // }, {value: 0}).value
    // data[data.length] = {
    //     value: total / 0.8 - total,
    // } 
    // data.unshift(data.pop())
    function render(id) {
        const flag = id === 'meetingRoomDailyLeft' ? 1 : 0
        var option = {
            color: ['#23F9EC', '#154954', '#122B2E'],
            tooltip: {
                trigger: 'item',
                // formatter: "{a} <br/>{b}: {c} ({d}%)"
                formatter: "{b}:{c}"
            },
            series: [

                {
                    name: '会议室',
                    type: 'pie',
                    radius: ['45%', '60%'],
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },

                    startAngle: -55,
                    data: []
                },
                {
                    name: '使用率',
                    type: 'pie',
                    radius: ['0%', '25%'],
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    label: {
                        position: 'center',
                        color: 'rgba(255,255,255,0.8)',
                        formatter: '{c}%'

                    },
                    tooltip: {
                        trigger: 'item',
                        // formatter: "{a} <br/>{b}: {c} ({d}%)"
                        formatter: "使用率{c}%"
                    },
                    data: []
                },

            ]
        };
        let data
        if (flag) {

            data = {
                token: info.token,
                result: 'count(1) used_room,(select count(1)  from t_meeting_room where place_id  =\'9\' and active_status=\'0\' and del_flag =\'0\')  all_room',
                tableName: 't_meeting_room_apply_request',
                condition: '1=1  and  (now() between start_date and end_date ) and pass_flag =\'0\'  and place_id =\'9\' and del_flag=\'1\''
            }
        } else {
            data = {
                token: info.token,
                result: 'count( distinct room_id ) ,count(distinct room_id)/57',
                tableName: 't_business_room_apply_request',
                condition: "1=1  and  (now() between start_date and end_date ) and pass_flag =\'0\' and identity_card is not null"
            }
        }
        console.log(data)
        $.ajax({
            url: info.base_url + '/ccp/test/dynamicSelect',
            type: 'post',
            dataType: 'json',
            data: data,
            success: function (res) {
                if (flag) {
                    option.series[0].data = [{
                        value: res[0]['used_room'], name: '使用量'
                    }, {
                        value: res[0]['all_room'] - res[0]['used_room'], name: '剩余量'
                    }]
                    option.series[1].data = [
                        { value: ((res[0]['used_room'] / res[0]['all_room']) * 100).toFixed(0) }
                    ]
                    $('.meetingRoomDaily .lefts .info').text(res[0]['used_room'] + '/' + res[0]['all_room'])
                } else {
                    option.series[0].data = [{
                        value: res[0]['count( distinct room_id )'], name: '使用量'
                    }, {
                        value: 57 - parseInt(res[0]['count( distinct room_id )']), name: '剩余量'
                    }]
                    option.series[1].data = [
                        { value: (res[0]['count(distinct room_id)/57'] * 100).toFixed(0) }
                    ]
                    $('.meetingRoomDaily .rights .info').text(res[0]['count( distinct room_id )'] + '/' + 57)
                }
                echarts.init(document.getElementById(id)).setOption(option)
            }

        })
    }

    render('meetingRoomDailyLeft')
    render('meetingRoomDailyRight')
})()

